#pragma once

#include <iostream>
#include <string>
#include <cerrno>
#include <cstring>
#include <cstdlib>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#define FIFO_FILE "./myfifo"
#define MODE 0664

enum
{
    FIFO_CREATE_ERR = 1,
    FIFO_DELETE_ERR,
    FIFO_OPEN_ERR
};

class InitPipe
{
public:
    InitPipe()
    {
        int n = mkfifo(FIFO_FILE,MODE);
        //n=0 创建成功  n=-1 失败
        if(n<0)
        {
            perror("mkfifo");
            exit(FIFO_CREATE_ERR);
        }
    }
    ~InitPipe()
    {
        int m =unlink(FIFO_FILE);
        if(m<0)
        {
            perror("unlink");
            exit(FIFO_DELETE_ERR);
        }
    }

};